package com.ftg.learn.controller;

import com.ftg.learn.entity.SysRole;
import com.ftg.learn.service.RoleService;
import com.ftg.learn.util.PageEx;
import com.ftg.learn.util.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 布衣
 */
@RestController
@RequestMapping("/role")
@Tag(name = "角色接口")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/list")
    public R<PageEx<SysRole>> list(
            @RequestParam(required = false,name="roleName") String roleName,
            @RequestParam(name="pageNum") Integer pageNum,
            @RequestParam(name="pageSize") Integer pageSize
    ){
       return roleService.list(roleName,pageNum,pageSize);
    }

    @PostMapping("/add")
    public R<Integer> add(@RequestBody SysRole role){
        return roleService.add(role);
    }

    @PutMapping("/update")
    public R<Integer> update(@RequestBody SysRole role){
        return roleService.update(role);
    }

    @DeleteMapping("/deleteById/{id}")
    public R<Integer> deleteById(@PathVariable Long id){
        return roleService.deleteById(id);
    }

    @DeleteMapping("/deleteByIds")
    public R<Integer> deleteByIds(@RequestParam List<Long> ids){
        return roleService.deleteByIds(ids);
    }

}
